package com.healthy.education.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.healthy.common.log.annotation.Log;
import com.healthy.common.log.enums.BusinessType;
import com.healthy.common.security.annotation.RequiresPermissions;
import com.healthy.education.domain.UserCoursePurchases;
import com.healthy.education.service.IUserCoursePurchasesService;
import com.healthy.common.core.web.controller.BaseController;
import com.healthy.common.core.web.domain.AjaxResult;
import com.healthy.common.core.utils.poi.ExcelUtil;
import com.healthy.common.core.web.page.TableDataInfo;

/**
 * 课程购买记录Controller
 * 
 * @author 束伟
 * @date 2024-03-29
 */
@RestController
@RequestMapping("/UserCoursePurchases")
public class UserCoursePurchasesController extends BaseController
{
    @Autowired
    private IUserCoursePurchasesService userCoursePurchasesService;

    /**
     * 查询课程购买记录列表
     */
    @RequiresPermissions("education:UserCoursePurchases:list")
    @GetMapping("/list")
    public TableDataInfo list(UserCoursePurchases userCoursePurchases)
    {
        startPage();
        List<UserCoursePurchases> list = userCoursePurchasesService.selectUserCoursePurchasesList(userCoursePurchases);
        return getDataTable(list);
    }

    /**
     * 导出课程购买记录列表
     */
    @RequiresPermissions("education:UserCoursePurchases:export")
    @Log(title = "课程购买记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserCoursePurchases userCoursePurchases)
    {
        List<UserCoursePurchases> list = userCoursePurchasesService.selectUserCoursePurchasesList(userCoursePurchases);
        ExcelUtil<UserCoursePurchases> util = new ExcelUtil<UserCoursePurchases>(UserCoursePurchases.class);
        util.exportExcel(response, list, "课程购买记录数据");
    }

    /**
     * 获取课程购买记录详细信息
     */
    @RequiresPermissions("education:UserCoursePurchases:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userCoursePurchasesService.selectUserCoursePurchasesById(id));
    }

    /**
     * 新增课程购买记录
     */
    @RequiresPermissions("education:UserCoursePurchases:add")
    @Log(title = "课程购买记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserCoursePurchases userCoursePurchases)
    {
        return toAjax(userCoursePurchasesService.insertUserCoursePurchases(userCoursePurchases));
    }

    /**
     * 修改课程购买记录
     */
    @RequiresPermissions("education:UserCoursePurchases:edit")
    @Log(title = "课程购买记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserCoursePurchases userCoursePurchases)
    {
        return toAjax(userCoursePurchasesService.updateUserCoursePurchases(userCoursePurchases));
    }

    /**
     * 删除课程购买记录
     */
    @RequiresPermissions("education:UserCoursePurchases:remove")
    @Log(title = "课程购买记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userCoursePurchasesService.deleteUserCoursePurchasesByIds(ids));
    }
}
